package com.two.lbms.lzs.controller;

import com.two.lbms.base.BaseController;
import com.two.lbms.base.ResultInfo;
import com.two.lbms.lzs.query.AdminQuery;
import com.two.lbms.lzs.service.AdminService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("admin")
public class AdminController extends BaseController {

    //2. 依赖注入 Service 层方法
    @Resource
    private AdminService adminService; // Bean对象
    @RequestMapping("index")
    public String toAdminPage() {
        return "lzs/admin";
    }

    /**
     * 3.多条件分页查询 图书馆管理者
     * @param query
     * @return
     */
    @ResponseBody
    @RequestMapping("admin")
    public Map<String,Object> queryAdminByParams (AdminQuery query){
        Map<String,Object> map=adminService.queryAdminByParams(query);
        System.out.println(map);
        //4. 返回 service 层方法
        return adminService.queryAdminByParams(query);
    }

    @RequestMapping("toAddPage")
    public String toAdminAddPage() {
        return "lzs/add";
    }
    @PostMapping("add")
    @ResponseBody
    public ResultInfo addAdmin(AdminQuery query) {
        adminService.saveAdmin(query);
        return success("添加成功");
    }
    @DeleteMapping("delete")
    @ResponseBody
    public ResultInfo deleteAdmin(Integer id) {
        adminService.deleteAdmin(id);
        return success("删除成功");
    }
}
